package com.steel.yfmall.cloud.assistant.listener;

import com.alibaba.fastjson.JSON;
import com.steel.yfmall.cloud.assistant.stock.SteelBaseFreightBeanService;
import com.steel.yfmall.cloud.assistant.po.stock.SteelBaseFreightBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class SteelBaseFreightSyncListener {

    @Resource
    private SteelBaseFreightBeanService steelBaseFreightBeanService;

    /**
    * @Title: 运费信息同步
    * @Description: (这里用一句话描述这个方法的作用)
    * @date 2020/12/8 16:17
    * @author lang
    * @param []
    * @return void    返回类型
    * @version 1.0
    */
    @JmsListener(destination = "freight_info_synchronization")
    public void doSteelBaseFreightSync(String onMsgText){
        SteelBaseFreightBean paraBean = null;
        try{
            log.info("freight_info_synchronization" + onMsgText);
            if (StringUtils.isBlank(onMsgText)) {
                log.error("同步运费信息:参数为空！");
                return;
            }

            paraBean = JSON.parseObject(onMsgText, SteelBaseFreightBean.class);
            if(paraBean == null || StringUtils.isBlank(paraBean.getName())){
                log.error("同步运费信息必传参数为空："+JSON.toJSONString(paraBean));
                return;
            }


            if(!steelBaseFreightBeanService.insertOrUpdateFreightBeanInfo(paraBean)){
                log.error("新增或修改运费同步信息失败:"+JSON.toJSONString(paraBean));
            }

            log.info("新增或修改运费同步信息成功，本次同步运费单据编号为："+paraBean.getName());
        }catch (Exception e){
            log.error(onMsgText + "同步运费信息失败", e);
        }
    }
}
